<template>
  <div class="opera-project-container">
    <el-row>

      <!-- :disabled="status=='detail'" -->
      <el-form :model="requestParams"
               status-icon
               :rules="rules"
               ref="requestParams"
               label-width="150px"
               class="demo-requestParams">
        <el-tabs v-model="activeName"
                 @tab-click="handleClick">
          <el-tab-pane label="基本信息"
                       name="first"
                       key='1'>
          </el-tab-pane>
          <el-tab-pane key='2'
                       label="浙里建项目信息"
                       v-if="isDustryPro==true"
                       name="second">
          </el-tab-pane>
          <el-tab-pane key='3'
                       label="浙里建造特有信息"
                       v-if="isDustryPro==true"
                       name="third">
          </el-tab-pane>
        </el-tabs>

        <el-col :span="24">
          <ProjectBaseInfoComponent :isDustryPro.sync="isDustryPro"
                                    :businessType.sync="businessType"
                                    :objRowRequest.sync="objRowRequestf"
                                    :depArr.sync="deptArr"
                                    v-show="activeName=='first'"></ProjectBaseInfoComponent>
          <ZheliConstructProjectInfor v-show="activeName=='second'"
                                      :objRowRequest.sync="objRowRequestf"></ZheliConstructProjectInfor>
          <ZheliConstructSpecInfo v-show="activeName=='third'"
                                  :objRowRequest.sync="objRowRequestf"></ZheliConstructSpecInfo>
        </el-col>
      </el-form>
      <el-col :span="24"
              class="bottom-box">
        <el-button @click="onstep(activeName)"
                   type="primary"
                   v-if="isDustryPro && (activeName === 'first' || activeName == 'second')">下一步</el-button>
        <el-button @click="onBack">取消</el-button>
        <el-button @click="editProject"
                   v-if="$route.query.status!=='detail' &&(isDustryPro === false || activeName === 'third') "
                   :type="$route.query.status=='detail'?'info':'primary'">确定</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { ProjectListApi } from '@/services/ProjectCenter'
import { operaProjectMixin } from '@/mixins/operaProjectMixins'
import ProjectBaseInfoComponent from './components/ProjectBaseInfoComponent'
import ZheliConstructProjectInfor from './components/ZheliConstructProjectInfor'
import ZheliConstructSpecInfo from './components/ZheliConstructSpecInfo'
export default {
  mixins: [operaProjectMixin],
  components: {
    ProjectBaseInfoComponent,//基本信息
    ZheliConstructProjectInfor,//浙里建项目信息
    ZheliConstructSpecInfo,//浙里建造特有信息
  },
  data () {
    return {
      businessType: [],
      projectId: 0,
      requestParams: {},
      objRowRequestf: {
        underground_area: '',
        aboveground_area: '',
        land_area: '',
        greening_rate: '',
        plot_rate: '',
        assembly_rate: '',
        supervisor_company: '',
        supervisor_leader_name: '',
        survey_leader_name: '',
        construction_leader_name: '',
        survey_company: '',
        construction_company: '',
        design_leader_name: '',
        design_company: '',
        subcontract_scope: '',
        laborer: '',
        labor_capital_leader_name: '',
        is_sync: 0,//默认是非同步的
        is_converge: '',//是否集中建设
        is_sync: 0,//0：不同步； 1：同步
        project_code: '',//项目代码
        is_indust_project: '',
        project_name: '',
        nick_name: '',
        business_type: '',
        // business_type_list: [],
        major_type: '',
        building_type: '',
        license_number: '',
        leader_name: '',
        // leader_phone: '',
        // leader_id: '',
        dept_no: '',
        address: '',
        lon: '',
        lat: '',
        lonlat: '',
        floorage: '',
        status: '',
        contract_total: '',
        sign_time: '',
        application: '',
        img: '',
        // img_url: '',
        project_attr: {},
        count: 0,
        project_license_no: '',
        jt_project_id: 0,
        jt_project_name: '',
        province: '',
        province_no: '',
        city: '',
        city_no: '',
        area: '',
        area_no: '',
        is_use_bim: '',//是否运用bim
        is_wisdom: '',//是否智慧工地项目
        project_ext_id: '',
        project_license_no: '',
        project_name: '',
        construct_nature: '',
        project_type: '',
        invest_nature: '',
        approval_auth_level: '',
        totall_cost: '',
        total_invest: '',
        street: '',
        street_no: '',
        quality_sup_station: '',
        quality_safe_sup_no: '',
        address: '',
        project_station: '',
        total_build_area: '',
        lon: '',
        lat: '',
        len: '',
        width: '',
        contract_price: '',
        contract_start_date: '',
        contract_end_date: '',
        contract_days: '',
        plan_start_date: '',
        plan_end_date: '',
        project_status: '',
        project_usage: '',
        is_important: '',
        video_install_status: '',
        build_company: '',
        build_credit_code: '',
        build_leader_name: '',//建设单位负责人
        is_indust_project: '',
        org_type: '',//组织方式
        struct_type: '',
        prefabrication_rate: '',
        assembly_con_position: '',
        is_full_trim: '',
        floor_num: '',
        full_trim_area: '',
        assembly_area: '',
      },
      isDustryPro: false,//是否工业化项目
      activeName: 'first',
      tabsArr: [{ id: 1, label: '基本信息', name: 'first' }, { id: 2, label: '浙里建项目信息', name: 'second' }, { id: 3, label: '浙里建造特有信息', name: 'third' }],
    }
  },
  methods: {
    handleClick (val) {
      console.log('val=', val)
    },
    // judgeIndustryPro () {//判断是否为工业化项目
    //   let currentLocInfo = window.location.href;
    //   // let industryPro = 'localhost:8081'
    //   // //zljz.hibuilding.cn
    //   let industryPro = '//zljz.hibuilding.cn';//是否为当使用域名（http://zljz.hibuilding.cn/login
    //   if (currentLocInfo.indexOf(industryPro) != -1) {
    //     this.objRowRequestf.is_indust_project = '1';
    //     this.isDustryPro = true;//工业化项目
    //   }
    // },
    getProjectInfo () {
      //项目详情
      let projectId = this.$route.query.project_id || this.projectId;
      window.localStorage.setItem('editProjectInfo', JSON.stringify({ id: projectId }))
      console.log('测试项目主键值 projectId=', projectId)
      ProjectListApi.getProjectInfo({
        params: {
          project_id: projectId,//项目主键值
        }
      }).then((res) => {
        let isIndustryPro = res.data.is_indust_project;//是否工业化项目
        if (isIndustryPro == 1) {
          this.isDustryPro = true;
        }
        this.objRowRequestf = res.data;
        let lon = res.data.lon;
        let lat = res.data.lat;
        let businessTypeV = res.data.business_type;
        this.objRowRequestf.lonlat = lon + '-' + lat;
        let deptNo = this.objRowRequestf.dept_no;
        let deptName = this.objRowRequestf.dep_name;//部门名称
        this.deptArr = [];//项目部下拉
        this.deptArr.push({
          key: String(deptNo),
          value: String(deptNo),
          label: deptName
        });
        this.objRowRequestf.dept_no = String(deptNo);//项目部
        this.businessType = businessTypeV.split(',');
        console.log(this.objRowRequestf.business_type, '8888objRowRequestf=', this.objRowRequestf, 'businessType=', this.businessType, 'deptArr=', this.deptArr)
      }).catch((error) => {
        console.log(error)
      })
    }
  },
  watch: {//监听
    objRowRequestf: {
      handler (n, o) {
        this.requestParams = n;
        console.log('父组件 objRowRequestf=', n, 'requestParams=', this.requestParams)
      },
      deep: true
    }
  },
  created () {
    let statusV = this.$route.query.status;
    // if (statusV == 'create' || statusV == 'update') {//新增、编辑
    // this.judgeIndustryPro();//判断是否为工业化项目
    // }
    if (this.$route.query.addType === 'industry') {
      //新增工业化项目
      this.isDustryPro = true
      this.objRowRequestf.is_indust_project = '1';
    } else {
      this.objRowRequestf.is_indust_project = '0';
    }
    let local = JSON.parse(window.localStorage.getItem('editProjectInfo') || '{}')
    this.projectId = local.id || 0;
    let projectId = this.$route.query.project_id || this.projectId;//项目的主键值
    if (projectId) {
      this.getProjectInfo();//项目详情
    }
  }
}
</script>

<style lang="scss" scoped>
.opera-project-container {
  padding: 0px 20px 20px 20px;
  .bottom-box {
    // padding-left: 190px !important;
    text-align: center;
  }
}
</style>